import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class LoadingContainer extends StatelessWidget {
  final bool loading;
  final Widget child;

  //加载动画是否叠加在上层
  final bool cover;

  const LoadingContainer(
      {Key key,
      @required this.child,
      @required this.loading,
      this.cover = false})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (cover) {
      return new Stack(
        children: [child, loading ? _loadingView() : null],
      );
    } else {
      return loading ? _loadingView() : child;
    }
  }

  Widget _loadingView() {
    return new Center(
      child: CircularProgressIndicator(),
    );
  }
}
